using System.IO;
using System.Text;
using System.Xml;

namespace OracleInternal.BinXml
{
	internal sealed class ObxmlTextStream : XmlTextWriter
	{
		private char[] m_chars = new char[4096];

		internal ObxmlTextStream(StringBuilder sb)
			: base(new StringWriter(sb))
		{
			base.Formatting = Formatting.Indented;
			base.Indentation = 2;
			base.IndentChar = ' ';
		}

		internal void AppendCData(string cdata)
		{
			WriteCData(cdata);
			Flush();
		}

		internal void AppendComment(string comment)
		{
			WriteComment(comment);
			Flush();
		}

		internal void AppendData(byte[] data)
		{
			char[] array = m_chars;
			if (data.Length / 2 > 4096)
			{
				array = new char[data.Length / 2];
			}
			int charCount = data.Length / 2;
			ObxmlStream.Unicode_AL16UTF16_CHARSET.ConvertBytesToChars(data, 0, data.Length, array, 0, ref charCount);
			WriteChars(array, 0, charCount);
			Flush();
		}

		internal void Clear()
		{
			Close();
		}
	}
}
